package cn.bgs.mq.consumer;


import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @Author:YiChen
 * @program: IntelliJ IDEA
 * @Description:
 * @Created 2021/10/14-9:09
 */
@Component
@Slf4j
public class DeadConsumer {

    //死信队列接收消息
    @RabbitListener(queues = "shop.dead.queue")
    public void messageDead(Message message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
        String msg = new String(message.getBody());
        log.info("当前时间：{}，收到死信队列消息队列Id：{}",new Date().toString(),msg);
        channel.basicAck(tag,false);

    }
}
